package com.ternnetwork.cms.controller.carousel;

import java.io.PrintWriter;
import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.ternnetwork.cms.model.carousel.CarouselContent;
import com.ternnetwork.cms.service.carousel.CarouselContentService;
import com.ternnetwork.commons.model.http.BaseResponse;
import com.ternnetwork.commons.utils.PrintWriterUtils;
import com.ternnetwork.persistence.page.Page;


@Controller@Scope("prototype")
@RequestMapping("/cms/carousel/content/*")
public class CarouselContentController {
	
	@Resource
	private CarouselContentService carouselContentService;

	
	@RequestMapping("manage.htm")
	public ModelAndView manage(String carouselId){
		return new ModelAndView("/WEB-INF/view/cms/carousel/carousel_content_manage.jsp").addObject("carouselId", carouselId);
	}
	
	@RequestMapping("add.htm")
	public @ResponseBody BaseResponse add(CarouselContent t){
		return carouselContentService.idoAdd(t);
	}
	
	@RequestMapping("update.htm")
	public @ResponseBody BaseResponse update(CarouselContent t){
	    return carouselContentService.idoUpdate(t);
	}
	
	@RequestMapping("delete.htm")
	public @ResponseBody BaseResponse delete(long id){
		return carouselContentService.idoDeleteById(id);
	}
	
	@RequestMapping("query.htm")
	public void query(PrintWriter out,HttpServletResponse response,String order,int limit, int offset,String carouselId){
		Page page=Page.createPage(limit, offset);
		PrintWriterUtils.printString(out, response, carouselContentService.queryToJsonStr(page,carouselId));
    }
	
	@RequestMapping("findByCode.htm")
	public @ResponseBody List<CarouselContent> findAllByCarouselCode(String carouselCode){
			return carouselContentService.findAllByCarouselCode(carouselCode);
	}
}
